
import bpy

import 全局控制.Node.插座.bl_插座基类 as 插座基类
import 节点.Core.bl_UI配色 as 配色

import engine.initLIB.load_dll as engineLib
import ctypes







def f_socketVec_Update(self, context):
	data = tuple(self.default_value)
	engineLib.flexCAPI.f_bl_插座传入数据(ctypes.c_wchar_p(self.node.id_data.name), 
										ctypes.c_wchar_p(self.node.name), 
										ctypes.c_wchar_p(self.identifier), 
										ctypes.py_object(data),
										ctypes.c_bool(self.is_output)
										)
	#print('f_socketVec_Update = ', context, self)
	if context :
		self.id_data.f_节点数据更新_更新树([self.node])
		

class C_Socket_Vec2(插座基类.C_Socket_基类):
	default_value = bpy.props.FloatVectorProperty(size=2, default=(0.0, 0.0), update=f_socketVec_Update)
	
	def __init__(self):
		super(C_Socket_Vec2, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text, expand=True)
		else:
			layout.label(text=text)
		
	def draw_color(self, context, node):
		return (0.0, 1.0, 0.0, 1.0)
		
	def f_getData(self):
		if self.is_linked:
			return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		else:
			return self.m_Value

	def f_setData(self, data):
		self.m_Value = data
		f_socketVec_Update(self, None)
		
	def f_update(self):
		f_socketVec_Update(self, None)






class C_Socket_Vec3(插座基类.C_Socket_基类):
	default_value = bpy.props.FloatVectorProperty(default=(0.0, 0.0, 0.0), update=f_socketVec_Update)
	
	def __init__(self):
		super(C_Socket_Vec3, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text='vec3:'+text )
		else:
			layout.label(text=text)
		
	def draw_color(self, context, node):
		return (0.0, 1.0, 0.0, 1.0)
		
	def f_getData(self):
		if self.is_linked:
			return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		else:
			return self.default_value

	def f_setData(self, data):
		self.default_value = data
		f_socketVec_Update(self, None)
		
	def f_update(self):
		f_socketVec_Update(self, None)











class C_Socket_Vec4(插座基类.C_Socket_基类):
	default_value = bpy.props.FloatVectorProperty(size=4, default=(0.0, 0.0, 0.0, 0.0), update=f_socketVec_Update)
	
	def __init__(self):
		super(C_Socket_Vec4, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text )
		else:
			layout.label(text=text)
		
	def draw_color(self, context, node):
		return (0.0, 1.0, 0.0, 1.0)
		
	def f_getData(self):
		return None

	def f_setData(self, data):
		if self.is_output == False:
			self.default_value = data

	def f_update(self):
		f_socketVec_Update(self, None)







class C_Socket_iVec2(插座基类.C_Socket_基类):
	default_value = bpy.props.IntVectorProperty(size=2, default=(0, 0), update=f_socketVec_Update)
	
	def __init__(self):
		super(C_Socket_iVec2, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text )
		else:
			layout.label(text='ivec2:'+text)
		
	def draw_color(self, context, node):
		return 配色.g_矢量v2插座颜色
		
	def f_getData(self):
		if self.is_linked:
			return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		else:
			return self.default_value

	def f_setData(self, data):
		self.default_value = data
		f_socketVec_Update(self, None)
	def f_update(self):
		f_socketVec_Update(self, None)


class C_Socket_iVec3(插座基类.C_Socket_基类):
	default_value = bpy.props.IntVectorProperty(default=(0, 0, 0), update=f_socketVec_Update)
	
	def __init__(self):
		super(C_Socket_iVec3, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text='ivec3:'+text )
		else:
			layout.label(text='ivec3'+text)
		
	def draw_color(self, context, node):
		return 配色.g_矢量v3插座颜色
		
	def f_getData(self):
		if self.is_linked:
			return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		else:
			return self.default_value
	def f_setData(self, data):
		self.default_value = data
		f_socketVec_Update(self, None)
	def f_update(self):
		f_socketVec_Update(self, None)
















class C_Socket_uVec2(插座基类.C_Socket_基类):
	default_value = bpy.props.IntVectorProperty(default=(0, 0), min=0, update=f_socketVec_Update)
	
	def __init__(self):
		super(C_Socket_uVec2, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text )
		else:
			layout.label(text='uvec2:'+text)
		
	def draw_color(self, context, node):
		return 配色.g_矢量v2插座颜色
		
	def f_getData(self):
		if self.is_linked:
			return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		else:
			return self.default_value
	def f_setData(self, data):
		self.default_value = data
		f_socketVec_Update(self, None)
	def f_update(self):
		f_socketVec_Update(self, None)




class C_Socket_uVec3(插座基类.C_Socket_基类):
	default_value = bpy.props.IntVectorProperty(default=(0, 0, 0), min=0, update=f_socketVec_Update)
	
	def __init__(self):
		super(C_Socket_uVec3, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text )
		else:
			layout.label(text='uvec3:'+text)
		
	def draw_color(self, context, node):
		return 配色.g_矢量v3插座颜色
		
	def f_getData(self):
		if self.is_linked:
			return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		else:
			return self.default_value
	def f_setData(self, data):
		self.default_value = data
		f_socketVec_Update(self, None)
	def f_update(self):
		f_socketVec_Update(self, None)









class C_Socket_iVec4(插座基类.C_Socket_基类):
	default_value = bpy.props.IntVectorProperty(size=4, default=(0, 0, 0, 0), update=f_socketVec_Update)
	
	def __init__(self):
		super(C_Socket_iVec4, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text, expand=True, emboss=True, invert_checkbox=True)
		else:
			layout.label(text='ivec4:'+text)
		
	def draw_color(self, context, node):
		return (0.0, 1.0, 0.0, 1.0)
		
	def f_getData(self):
		return None

	def f_setData(self, data):
		if self.is_output == False:
			self.default_value = data

	def f_update(self):
		f_socketVec_Update(self, None)








class C_Socket_uVec4(插座基类.C_Socket_基类):
	default_value = bpy.props.IntVectorProperty(size=4, default=(0, 0, 0, 0), min=0, update=f_socketVec_Update)
	
	def __init__(self):
		super(C_Socket_uVec4, self).__init__()
		
	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text, expand=True)
		else:
			layout.label(text='uvec4:'+text)
		
	def draw_color(self, context, node):
		return 配色.g_矢量插座颜色
	def f_getData(self):
		return None
	def f_setData(self, data):
		self.default_value = data
	def f_update(self):
		f_socketVec_Update(self, None)










class C_Socket_矩阵3X3(插座基类.C_Socket_基类):
	def __init__(self):
		super(C_Socket_矩阵3X3, self).__init__()

	def draw(self, context, layout, node, text):
		layout.label(text='M3X3:'+text)
	def draw_color(self, context, node):
		return 配色.g_矢量插座颜色
		
	def f_getData(self):
		return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.name))
		
	def f_setData(self):
		return None








class C_Socket_矩阵4X4(插座基类.C_Socket_基类):
	def __init__(self):
		super(C_Socket_矩阵4X4, self).__init__()

	def draw(self, context, layout, node, text):
		layout.label(text='M4X4:'+text)
	def draw_color(self, context, node):
		return 配色.g_矢量插座颜色
		
	def f_getData(self):
		return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.name))
		
	def f_setData(self):
		return None











class C_Socket_顶点索引(插座基类.C_Socket_基类):
	def __init__(self):
		super(C_Socket_顶点索引, self).__init__()

	def draw(self, context, layout, node, text):
		layout.label(text=text+":[[int32]]")
		
	def draw_color(self, context, node):
		return (0.0, 0.0, 1.0, 1.0)
		
	def f_getData(self):
		return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
	def f_setData(self, data):
		pass




classes = (
	C_Socket_Vec2,
	C_Socket_Vec3,
	C_Socket_Vec4,

	C_Socket_iVec2,
	C_Socket_iVec3,
	C_Socket_iVec4,

	C_Socket_uVec3,
	C_Socket_uVec4,


	C_Socket_矩阵3X3,
	C_Socket_矩阵4X4,



	C_Socket_顶点索引,

)

def register():
	for c in classes:
		bpy.utils.register_class(c)
	pass	

def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)
	pass
	




